package com.example.websocket.websocket.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: websocket
 * @description: 跨域配置
 * @author: fks
 * @create: 2025-03-23 20:32
 **/

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/chat") // 配置允许跨域访问的路径
                .allowedOrigins("http://frontend-domain.com") // 允许的前端域名
                .allowCredentials(true); // 允许携带 Cookie
    }
}
